<template>
  <div>
    <a-card>
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-item label="申请单号">
                <a-input v-model="queryParam.applyNo" placeholder="请输入" />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="申请类型">
                <a-select v-model="queryParam.type" placeholder="请选择" :default-value="0">
                  <a-select-option :value="0">全部</a-select-option>
                  <a-select-option :value="1">受试者费用</a-select-option>
                  <a-select-option :value="2">研究者费用</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <template v-if="advanced">
              <a-col :md="6" :sm="24">
                <a-form-item label="申请者id">
                  <a-input v-model="queryParam.applyId" placeholder="请输入" />
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="收款人id">
                  <a-input v-model="queryParam.receiverId" placeholder="请输入" />
                </a-form-item>
              </a-col>
              <a-col :md="12" :sm="24">
                <a-form-model-item label="选择时间:" labelAlign="left">
                  <a-range-picker
                    v-decorator="['range-time-picker']"
                    show-time
                    valueFormat="YYYY-MM-DD HH:mm:ss"
                    @ok="confirmDate"
                  />
                </a-form-model-item>
              </a-col>
            </template>
            <a-col :md="(!advanced && 8) || 24" :sm="24">
              <span
                class="table-page-search-submitButtons"
                :style="(advanced && { float: 'right', overflow: 'hidden' }) || {}"
              >
                <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
                <a @click="toggleAdvanced" style="margin-left: 8px">
                  {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'" />
                </a>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <div class="table">
        <s-table ref="table" size="default" :rowKey="record => record.id" :columns="columns" :data="loadData">
          <span slot="createTime" slot-scope="text">{{ text | moment }}</span>
          <span slot="currentStatus" slot-scope="text, record">{{ record.status | filtersState }}</span>
          <span slot="action" slot-scope="text, record">
            <a @click="watchPayDetail(record)">查看</a>
          </span>
        </s-table>
      </div>
    </a-card>
  </div>
</template>
<script>
import { selectSubjectProject } from '@/api/cost/cost'
import { payAuditList } from '@/api/pay/pay'
export default {
  props: {
    activeIndex: {
      type: Number,
      default: 1
    }
  },
  components: {},
  watch: {
    activeIndex (val) {
      this.activeIndex = val
      console.log('状态', val)
    }
  },
  data () {
    return {
      projectList: 0,
      // tab切换时，更改queryParams中的状态字段。
      queryParam: {
        type: 1,
        status: this.activeIndex,
        proId: this.projectList
      },
      loadData: parameter => {
        console.log('loadData.parameter', this.queryParam)
        return payAuditList({ ...parameter, ...this.queryParam }).then(res => {
          return res
        })
      },
      advanced: false,
      columns: [
        {
          title: '项目ID',
          align: 'center',
          dataIndex: 'id'
        },
        {
          title: '申请单号',
          align: 'center',
          dataIndex: 'applyNo'
        },
        {
          title: '申请时间',
          align: 'center',
          dataIndex: 'createTime',
          scopedSlots: { customRender: 'createTime' }
        },
        {
          title: '付款类型',
          align: 'center',
          dataIndex: 'payType',
          scopedSlots: { customRender: 'payType' }
        },
        {
          title: '申请者ID',
          align: 'center',
          dataIndex: 'applyId'
        },
        {
          title: '收款者ID',
          align: 'center',
          dataIndex: 'receiverId'
        },
        {
          title: '申请金额',
          align: 'center',
          dataIndex: 'totalAmount',
          scopedSlots: { customRender: 'totalAmount' }
        },

        // {
        //   title: '付款时间',
        //   align: 'center',
        //   dataIndex: 'createTime',
        //   scopedSlots: { customRender: 'createTime' }
        // },
        {
          title: '付款单号',
          align: 'center',
          dataIndex: 'payNo',
          scopedSlots: { customRender: 'payNo' }
        },
        {
          title: '当前状态',
          align: 'center',
          dataIndex: 'currentStatus',
          scopedSlots: { customRender: 'currentStatus' }
        },
        {
          title: '操作',
          align: 'center',
          dataIndex: 'action',
          width: '150px',
          scopedSlots: { customRender: 'action' }
        }
      ]
    }
  },
  mounted () {
    console.log('6666666666')
    this.getProjectList()
  },
  methods: {
    // 请求项目列表
    getProjectList () {
      selectSubjectProject()
        .then(res => {
          this.projectList = res
          console.log(res, '项目列表')
        })
        .catch(() => {})
    },
    // 点击展开 详细搜索信息
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    // 查看某一个单号的付款详情
    watchPayDetail (e) {
      this.$router.push({
        name: 'PayDetail',
        query: {
          id: e.id
        }
      })
    },
    // 时间选择器
    confirmDate (e) {
      console.log(e)
      this.queryParam.beginData = e[0]
      this.queryParam.endData = e[1]
    }
  },
  filters: {
    filtersState (val) {
      if (val === 1) {
        return '待提交'
      } else if (val === 2) {
        return 'PI待审核'
      } else if (val === 3) {
        return 'PI已驳回'
      } else if (val === 4) {
        return 'PM待审核'
      } else if (val === 5) {
        return 'PM已驳回'
      } else if (val === 6) {
        return '待支付'
      } else if (val === 7) {
        return '保税中'
      } else if (val === 8) {
        return '已完成'
      }
    }
  }
}
</script>
<style>
.top-tab {
  display: flex;
  justify-content: space-between;
  cursor: pointer;
  margin-bottom: 40px;
}
.active-class {
  border-bottom: 3px solid #3c92ff;
  font-size: 18px;
}
.normal {
  font-size: 18px;
}
</style>
